<!DOCTYPE html>
<html>
<head lang="en">
    <meta charset="utf-8"><meta charset="utf-8">
    <meta name="viewport" content="width=device-width,maximum-scale=1.0,user-scalable=no"/>
    <title>洛克王国-滚蛋小游戏</title>
    <style>
        body,div,dl,dt,dd,ul,ol,li,h1,h2,h3,h4,h5,h6,th,td,p,pre,form,input,textarea{padding: 0;margin: 0;}
        table{border-collapse: collapse;border-spacing: 0;}
        ol,ul{list-style:none;}
        img{border:0 none;display:block;}
        a{outline: none;outline:none;text-decoration: none;}
        a:focus{outline:none;-moz-outline:none;}
        em,strong{font-weight: normal;font-style: normal;}
        html,body{font: 14px/20px "5B8B4F53";height: 100%;overflow:hidden;background:#000;}
        .wrap{background: url(images/inputTxt.png) repeat;background-size:cover;width: 266px;height:307px;position: absolute;left: 50%;top: 50%;margin: -153px 0 0 -128px;}
        .w_txt,.w_btn{border: 0 none;background:0 none;width: 230px;height: 40px;position: absolute;top: 168px;left: 50%;margin-left: -115px;text-indent: 8px;}
        .w_btn{display: block;top: 225px;height: 60px;}
    </style>
    
    <script src="lib/easeljs-0.7.1.min.js"></script>
    <script src="lib/tweenjs-0.5.1.min.js"></script>
    <script src="lib/preloadjs-0.4.1.min.js"></script>
    <script src="lib/movieclip-0.7.1.min.js"></script>
    <script src="lib/soundjs-0.5.2.min.js"></script>

    <script src="common/common.js"></script>
    <script src="src/app.js"></script>
    <script src="src/loadingContent.js"></script>
    <script src="src/screenContent.js"></script>
    <script src="src/parameters.js"></script>
    <script src="loading.js"></script>
    <script src="main.js"></script>

    <body id="bodyMain" onload="initLoading();" style="background-color: #666666">

    <div id="inputNamePanel" class="wrap">
        <input class="w_txt" id="usernameInput" type="text" maxlength="8" value="请输入！如：坏运气" onfocus="javascript:inputFocus();">
        <a class="w_btn" id="wBtn" href="javascript:inputNamePanelStartGame();"></a>
    </div>

    <div id="loading" class="div-loading">
        <canvas id="canvasLoading" width="640" height="1008">
            sorry,your browser dosen't support html5
        </canvas>
        <style>
            *{
                margin: 0;
                padding: 0;
            }
            #a{
                display: block;
                background-color: gray;
            }
        </style>
    </div>
    <div id="main" class="div-main">
        <canvas id="canvas" width="640" height="1008">
            sorry,your browser dosen't support html5
        </canvas>
        <style>
            *{
                margin: 0;
                padding: 0;
            }
            #a{
                display: block;
                background-color: gray;
            }
        </style>
    </div>
    </body>

    <script language="JavaScript" type="text/javascript">

        var picArr=[];//记录大图小图的数组;
        var canvasLoading,canvas,stage,loadingStage,exportRoot;
        var queue;
        var scale=1;
        var picNum=0;//主文件已加载图片数量;
        var picTotal=0;//主文件图片数量总和;
        var loadingProgress=0;//loading百分比;

        var loadingPanel;//loading对象;
        var appPanel;//app主体对象;
        var screenPanel;//其他场景对象;
        var model=new createjs.MovieClip();//用于发送事件;

        var _fps,$time,$count = 0;

        init();

        function init()
        {
            inputNamePanelDisplay(false);//隐藏输入名称面板;
            // onBridgeInit();//朋友圈;
            tcssComplete();//监测代码;
            queue=new createjs.LoadQueue(true);

            var tmpStr=3;//getQueryString('heartNum');
            console.log('heartNum:',tmpStr);
            HEARTNUM=Number(tmpStr);



            SHARE_URL='http://roco.qq.com/act/a20141208game/index.html?heartNum='+HEARTNUM.toString();//分享地址;
        }

        //loading canvas加载完成的时候会调用该函数;
        function initLoading()
        {
            canvasLoading=document.getElementById('canvasLoading');

            loadingImages = loadingImages||{};

            var loader = new createjs.LoadQueue(false);
            loader.addEventListener("fileload", loadingHandleFileLoad);
            loader.addEventListener("complete", loadingHandleComplete);
            loader.loadManifest(loadingLib.properties.manifest);

            //initMain();


        }



        //loading过程中加载图片素材;
        function loadingHandleFileLoad(evt) {
            if (evt.item.type == "image") { loadingImages[evt.item.id] = evt.result; }
        }
        //loading素材加载完成;
        function loadingHandleComplete() {
            exportRoot = new loadingLib.loading();

            stage = new createjs.Stage(canvasLoading);
            stage.addChild(exportRoot);
            stage.update();

            createjs.Ticker.setFPS(loadingLib.properties.fps);
            createjs.Ticker.addEventListener("tick", stage);

            //初始化loading内容;
            loadingPanel=new loadingObj();

            //return;

            if(isLoadBigPic)
            {
                //加载大图;
                queue.setMaxConnections(5);
                queue.on('complete',imagesLoadComplete,this);
                queue.on('progress',imagesLoadProgress);

                var manifestLength=lib.properties.manifest.length;
                picArr=[].concat(lib.properties.manifest);
                for(var i=0;i<gamedataArr.length;i++)
                {
                    for (prop in gamedataArr[i].animations)
                    {
                        //console.log(prop,arr[i].animations[prop]);
                        for(var j=0;j<manifestLength;j++)
                        {
                            if(picArr[j])
                            {
                                if(prop==picArr[j].id)
                                {
                                    picArr.splice(j,1);
                                    j-=1;
                                }
                            }
                        }
                    }
                    picArr.push({id:'test'+ i.toString(),src:gamedataArr[i].images[0]});
                }
                console.log(picArr);
                queue.loadManifest(picArr);
            }
            else
            {
                //加载小图;
                initMain();
            }
        }

        function imagesLoadProgress(e)
        {
            loadingProgress= e.progress;
        }

        function imagesLoadComplete(e)
        {
            initMain();
        }

        //
        function initMain()
        {
            canvas = document.getElementById('canvas');
            images = images||{};

            picTotal=lib.properties.manifest.length;

            if(isLoadBigPic)
            {
                //加载大图 解析大图;
                for(var i=0;i<gamedataArr.length;i++)
                {
                    setImgItem(gamedataArr[i],lib,images);
                }

                for(var j=0;j<picArr.length;j++)
                {
                    //console.log(picArr[j]);
                    for(var k=0;k<picTotal;k++)
                    {
                        if(lib.properties.manifest[k].id==picArr[j].id)
                        {
                            images[picArr[j].id]=queue.getResult(picArr[j].id);
                        }
                    }
                }
                console.log('pic num:',picArr.length);
                initHandleComplete();
            }
            else
            {
                //加载小图;
                var loader = new createjs.LoadQueue(false);
                loader.addEventListener("fileload", initHandleFileLoad);
                loader.addEventListener("complete", initHandleComplete);
                loader.loadManifest(lib.properties.manifest);
            }
        }

        function initHandleFileLoad(evt) {
            picNum+=1;
            loadingProgress=picNum/picTotal;
            //console.log(loadingProgress);
            if (evt.item.type == "image") { images[evt.item.id] = evt.result; }
        }

        function initHandleComplete() {
            console.log('handleCompleteInit');

            exportRoot = new lib.main();

            stage = new createjs.Stage(canvas);
            stage.addChild(exportRoot);
            stage.update();

            if(isNeedFps)
            {
                _fps = new createjs.Text("0","900 36px Arial", "#000000");
                stage.addChild(_fps);
                $time = new Date().getTime();
            }


            createjs.Ticker.setFPS(lib.properties.fps);
            createjs.Ticker.addEventListener("tick", stageFun);

            createjs.EventDispatcher.initialize(model);

            //new app.init();
            screenPanel=new screenObj();
            screenPanel.init();

            appPanel=new appObj();
            appPanel.init();

            //test;
            //loadingNone();
            //gameStart();
        }

        //由于大图解析成小图需要一个过度时间3-4s,所以需要先用loading遮挡;
        function loadingNone()
        {
            stage.removeChild(loading);
            document.getElementById('loading').style.display="none";
        }

        //帧频显示;
        function stageFun()
        {
            if(isNeedFps)
            {
                $count++;
                var now = new Date().getTime();
                if( now-$time>1000 ){
                    _fps.text = "fps:"+ Math.round( $count*10000 / (now-$time))/10+'/'+lib.properties.fps;
                    $time = now;
                    $count = 0;
                }
            }
            stage.update();
        }

        function gameStart()
        {

        }

        function gameOver()
        {

        }

        function inputNamePanelStartGame()
        {
            //alert('inputNamePanelStartGame');
            username=document.getElementById('usernameInput').value;
            if(username=='请输入！如：坏运气'||username=='')
            {
                username='洛克小蛋蛋';
            }
            //alert(username);
            inputNamePanelDisplay(false);
            appPanel.startGame();
        }

        function inputNamePanelDisplay(arg)
        {
            if(arg==true)
            {
                document.getElementById('inputNamePanel').style.display='block';
            }
            else
            {
                document.getElementById('inputNamePanel').style.display='none';
            }
        }

        function inputFocus()
        {
            username=document.getElementById('usernameInput').value;
            if(username=='请输入！如：坏运气')
            {
                //username='默认名称';
                document.getElementById('usernameInput').value='';
            }
        }

        var sw=window.screen.width*0.9,sh=(sw*296)/256;
        function g(id){return document.getElementById(id);}
        if(window.screen.width<=640){
            g("inputNamePanel").style.width=sw+"px";
            g("inputNamePanel").style.height=sh+"px";
            g("inputNamePanel").style.marginLeft=-(sw/2)+"px";
            g("inputNamePanel").style.marginTop=-(sh/2)+"px";
            g("usernameInput").style.width=sw*0.9+"px";
            g("usernameInput").style.marginLeft=-(sw*0.9/2)+"px";
            g("usernameInput").style.top=sh*0.555+"px";
            g("wBtn").style.top=sh*0.735+"px";
            g("wBtn").style.width=sw*0.9+"px";
            g("wBtn").style.marginLeft=-(sw*0.9/2)+"px";
            g("wBtn").style.height=sh*0.2+"px";
        }

    </script>
</head>

</html><!--[if !IE]>|xGv00|a221b93aaaa31cf3dcd8f6ed331efa79<![endif]-->